/* typehints:start */
import { getSkillLevelTitle } from "../defines/skill_level_define";
import { GameRoot } from "../root";
/* typehints:end */

export class MapSiteAttr{
  constructor(){
    this.next = [];
    this.goWorld = false;
  }
}

export class MapSite{
  constructor(root){
    /** @type {GameRoot} */
    this.root = root;
    this.mapPos = null;
    this.attr = new MapSiteAttr();
  }

  set(mapPos, params = {}){
    this.mapPos = mapPos;
    this.attr = Object.assign(this.attr, params);

    return this;
  }

  getTitle(){
    abstract;
  }

  getDesc(){
    abstract;
  }

  // 判断人物是否可以移动
  isMove(pos){
    let text = '';
    let flag = this.attr.next.find(item => {
      let flag = true;
      // 判断是否有这个定位
      if(item.pos[0] != pos[0] || item.pos[1] != pos[1]) {
        text = `没有这条路`;
        flag = false;
      }

      // 判断是否需要特定技能
      if(item.skill){
        let findSkill = this.root.mainPlayer.getSkill(item.skill.key);
        let name = item.skill.key.split('/').reverse()[0];
        // 技能的熟练度不足也不能行走
        let skillNum = this.root.mainPlayer.data.skillsNum[item.skill.key] || 0;
        if(skillNum < item.skill.num) {
          flag = false;
          text = `无法行走，需要技能<${name}>熟练度大于<${getSkillLevelTitle(item.skill.num)}>`;
        }
        if(!findSkill) {
          flag = false;
          text = `无法行走，需要学会技能<${name}>`;
        }
      }

      // 判断是否需要特定对话
      if(item.dialogue){
        let findDialogue = this.root.worldData.dialogues.find(dialogue => {
          return dialogue == item.dialogue
        })
        if(!findDialogue) {
          let npc = this.root.worldMap.getIdNpcs(item.dialogue.split('-')[0])[0];
          flag = false;

          if(npc){
            text = `无法行走，先与${npc.getName()}对话一下吧`;
          } else {
            text = '系统错误，指定npc不存在！'
          }
        }
      }

      return flag;
    })

    return {
      flag, text
    }
  }

  onClick(){
    
  }

  onEnter(){

  }

  onLeave(){
    
  }

  update(dt){

  }
}